package com.kevis.webCommon.web.domain.response;

import com.kevis.webCommon.web.domain.convert.BaseClassEntity2TreeSelectVoMapper;
import com.kevis.webCommon.web.domain.response.module.ResultEasyuiTable;
import com.kevis.webCommon.web.domain.response.module.ResultTable;
import com.kevis.webCommon.web.domain.response.module.ResultTree;
import com.kevis.zhunblog.core.entities.BaseClassEntity;
import com.kevis.zhunblog.core.vo.TreeSelectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * ResultController
 *
 * @Author kevis
 * @Date 2023/3/31 14:34
 */
//@Component
public class ResultController {
    @Autowired
    private BaseClassEntity2TreeSelectVoMapper mapper;
    /**
     * 跳转到指定的页面
     *
     * @param path
     * @return
     */
    public ModelAndView jumpPage(String path) {
       return jumpPage(path,0);
    }

    public ModelAndView jumpPage(String path,Integer MvcClassID) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName(path);
        modelAndView.addObject("MvcClassID",MvcClassID);
        return modelAndView;
    }

    /**
     * 树形的表格数据展示
     * @param data
     * @return
     */
    protected ResultTable treeTable(Object data) {
        return ResultTable.dataTable(data);
    }

    /**
     * Describe: 返回数据表格数据 分页
     * Param data
     * Return 表格分页数据
     */
    protected static ResultTable pageTable(Object data, long count) {
        return ResultTable.pageTable(count, data);
    }

    /**
     * Describe: 返回数据表格数据 分页
     * Param data
     * Return 表格分页数据
     */
    protected static ResultEasyuiTable pageEasyuiTable(Object data, long count) {
        return ResultEasyuiTable.pageTable(count, data);
    }

    /**
     * Describe: 返回 Tree 数据
     * Param data
     * Return Tree数据
     */
    protected static ResultTree dataTreeObject(Object data) {
        ResultTree tree = new ResultTree();
        tree.setData(data);
        return tree;
    }

    /**
     * 返回树形结构的数据
     * @param data
     * @return
     */
    protected <T> ResultTree dataTree(List<T> data){
        ResultTree tree = new ResultTree();
        if(data != null && data.size() > 0) {
            if (data.get(0) instanceof BaseClassEntity) {
                List<BaseClassEntity> list = (List<BaseClassEntity>) data;

                List<TreeSelectVo> treeSelectVos = mapper.toConvertList(list);
//                for (TreeSelectVo selectVo : treeSelectVos) {
//                    List<TreeSelectVo> l1 =  new ArrayList<TreeSelectVo>();
//                    TreeSelectVo t1 = new TreeSelectVo();
//                    t1.setId("8766");
//                    t1.setTitle("nihao阿迪斯");
//                    l1.add(t1);
//                    selectVo.setChildren(l1);
//                }
                //List<TreeSelectVo> treeSelectVos = BaseClassEntity2TreeSelectVoMapper.INSTANCE.toConvertList(list);
                tree.setData(treeSelectVos);
            }
        }
//        for (T t : data){
//            if(t instanceof BaseClassEntity){
//                BaseClassEntity classEntity =  ((BaseClassEntity)t);
//
//            }
//        }

        return tree;
    }
}
